home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C++ / Applications / Nuntius 1.2 / src / Nuntius / UThread.h < prev    next >
Encoding:
Text File  |  1994-03-16  |  2.6 KB  |  102 lines  |  [TEXT/MPS ]

  1. // Copyright © 1992-1993 Peter Speck, speck@dat.ruc.dk. All rights reserved.
  2. // UThread.h
  3.  
  4. #define __UTHREAD__
  5.  
  6. class TProgress;
  7.  
  8. class TThread : public TObject
  9. {
  10.     public:
  11.         TProgress *GetProgress();
  12.         
  13.         void YieldTime(); // always yield
  14.         void CheckYield(); // yield only if enough time has passed
  15.  
  16.         void Abort();
  17.         // TThread::Abort(): This only marks the thread is having to be aborted.
  18.         // It does not call TThread::YieldTime.
  19.         // The last aborted or killed thread will be the first swapped in.
  20.         // When the thread is swapped in, it's aborted by Failure(0, 0) and the
  21.         // abort flag is cleared
  22.         
  23.         void Kill();
  24.         // TThread::Kill(): The thread is killed by marking it with "permanent abort",
  25.         // calls TThread::Yieldtime. No other threads gets time until the thread is
  26.         // gone, unless this threads marks another thread as being aborted/killed.
  27.         // (A killed thread is too an aborted thread)
  28.  
  29.         Boolean IsAborted();
  30.         Boolean IsKilled();
  31.         Boolean IsStarted();
  32.         
  33.         Boolean SetYieldDisable(Boolean disable);
  34.         
  35.         virtual const char *PeekShortDescription();
  36.         virtual void DumpDebugDescription();
  37.         
  38.         TThread();
  39.         pascal void Initialize();
  40.         void IThread(Boolean isMainThread, const char *debugDoingWhat);
  41.         virtual void Die();
  42.  
  43.     protected:
  44.         TProgress *fProgress;
  45.         unsigned long fLastYieldTick;
  46.         const char *fDebugDoingWhat;
  47.         Boolean fIsMainThread;
  48.         Boolean fIsStarted;
  49.  
  50.         void SaveState();    // called when swapping out
  51.         void RestoreState(); // called when swapping in
  52.         void DoAbortThread();
  53.  
  54.         virtual pascal void Free(); //virtual ~TThread(); // keep safe, may only be called by Die()
  55.  
  56.         virtual void SwapThread();
  57.         
  58.     private:
  59.         friend void InitUThread();
  60.         friend void CloseDownUThread();
  61.  
  62.         FailInfoPtr fSavedTopHandler;
  63.         Boolean fIsAborting;
  64.         Boolean fIsKilling;
  65.         Boolean fYieldIsDisabled;
  66. };
  67.  
  68. class TThreadList : public TList
  69. {
  70.     public:
  71.         TThread *ExecuteCommand(TCommand *command, const char *debugDoingWhat);
  72.         pascal void DeleteAll(); // do call KillAll()
  73.         void KillAll();
  74.         TThread *ThreadAt(ArrayIndex index);
  75.  
  76.         void DebugDump();
  77.         
  78.         virtual pascal void Initialize();
  79.         void IThreadList(const char *debugListDescription);
  80.         virtual pascal void Free(); // screams if any thread in list
  81.     private:
  82.         const char *fDescription;
  83. };
  84.  
  85. // For your service:
  86. extern TThread *gCurThread;
  87. extern TThreadList *gApplWideThreads;
  88. TThreadList *NewThreadList(const char *debugListDescription);
  89.  
  90.  
  91. // Management stuff
  92. void InitUThread();
  93. void CloseDownUThread();
  94. void DumpDebugThreadDescription();
  95.  
  96. // Only for subclasses
  97. TThread *MySchedule();
  98. void ThreadExecuteCommand(TCommand *command);
  99.  
  100. short GetNumThreads();
  101. extern TList *gAllThreads;
  102.